package com.paradox.aggregation.provider.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler,DynamicProxy{

    private Class targetInterface;

    public JdkProxy(Class targetInterface){
        this.targetInterface=targetInterface;
    }

    @Override
    public Object createProxy(){
        Object testService= Proxy.newProxyInstance(targetInterface.getClassLoader(),new Class[]{targetInterface},this);
        return testService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before proxy...");
        System.out.println("target is "+method.getDeclaringClass()+",args is "+args[0]);
        System.out.println("after proxy...");
        return null;
    }
}
